package org.coco.mvc.render.impl;

import org.coco.mvc.RequestProcessorChain;
import org.coco.mvc.render.ResultRender;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 内部异常处理器
 */
public class InternalErrorResultRender implements ResultRender {


    private Object exception;

    public InternalErrorResultRender(Object exception) {
        this.exception = exception;
    }

    @Override
    public void render(RequestProcessorChain requestProcessorChain) throws Exception {
        //服务内部发生错误，返回500.html页面
        HttpServletResponse response = requestProcessorChain.getResponse();
        HttpServletRequest request = requestProcessorChain.getRequest();
        System.out.println("发生异常："+exception);
        request.setAttribute("error",exception);
        request.getRequestDispatcher("/templates/500.html").forward(request,response);
    }
}
